<template>

  <div class="all">
    <div class="channel_top">
      <el-input placeholder="请输入渠道名、手机号查询" v-model="likeName" style="width: 400px; position: absolute; left: 200px;">
      </el-input>
      <el-button style="position: absolute;left: 650px;" @click="findchannelby">查询</el-button>
      <el-button style="position: absolute;left: 720px;" @click="addchannel">新增</el-button>
      <el-button style="position: absolute;left: 800px;" @click="delechannel">删除</el-button>
    </div>
    <div class="table1">
      <!-- 展示的表格组件 -->
      <el-table :data="channels" :row-class-name="tableRowClassName" @selection-change="handleSelectionChange">
        <!-- 表格中多选框组件 -->
        <el-table-column type="selection" width="55">
        </el-table-column>
        <el-table-column prop="channelId" label="序列号" width="140">
        </el-table-column>
        <el-table-column prop="channelName" label="渠道名" width="120">
        </el-table-column>
        <el-table-column prop="channelPhone" label="手机号" width="120">
        </el-table-column>
        <el-table-column prop="channelConsume" label="累计充值" width="120">
        </el-table-column>
        <el-table-column prop="channelRecharge" label="累计消费" width="120">
        </el-table-column>
        <el-table-column prop="channelMemberNum" label="会员数量" width="120">
        </el-table-column>
        <el-table-column prop="channelStat" :formatter="IsKill" label="状态" width="120">
        </el-table-column>
       <el-table-column label="操作" width="120">
          <template slot-scope="scope">
            <el-button @click="updatechannel(scope.row)" type="text" size="small">修改渠道商信息</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页组件 -->
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
        :current-page.sync="pages.current" :page-size="pages.size" layout="total, prev, pager, next"
        :total="pages.total">
      </el-pagination>

 <el-dialog title="修改渠道商" :visible.sync="updateShopFormVisible" @close="warClose">
             <el-form  label-width="80px">
               <el-form-item label="渠道编号">
               	<el-input v-model="channel.channelId" disabled="disabled"></el-input>
               </el-form-item>
           		<el-form-item label="渠道名">
           			<el-input v-model="channel.channelName"></el-input>
           		</el-form-item>
           		<el-form-item label="联系方式">
           			<el-input v-model="channel.channelPhone"></el-input>
           		</el-form-item>
               <el-form-item label="消费金额">
               	<el-input v-model="channel.channelConsume"></el-input>
               </el-form-item>
               <el-form-item label="充值金额">
               	<el-input v-model="channel.channelRecharge"></el-input>
               </el-form-item>
               <el-form-item label="会员数量">
               	<el-input v-model="channel.channelMemberNum" disabled="disabled"></el-input>
               </el-form-item>
               <el-form-item label="身份证号">
               	<el-input v-model="channel.channelIdNumber" ></el-input>
               </el-form-item>
               <el-form-item label="银行">
               	<el-input v-model="channel.channelBank" ></el-input>
               </el-form-item>
               <el-form-item label="银行账号">
               	<el-input v-model="channel.channelBankAccount" ></el-input>
               </el-form-item>
               <el-form-item label="状态">
               	<template>
               	  <el-radio v-model="channel.channelStat" label="1">启用</el-radio>
               	  <el-radio v-model="channel.channelStat" label="0">禁用</el-radio>
               	</template>
               </el-form-item>
              </el-form>
             <div slot="footer" class="dialog-footer">
               <el-button @click="updateShopFormVisible = false">取 消</el-button>
               <el-button type="primary" @click="updateWarOK">保存</el-button>
             </div>
           </el-dialog>


      <el-dialog title="新增渠道商" :visible.sync="addShopFormVisible" @close="shopClose">
             <el-form  label-width="80px">
               <el-form-item label="渠道名">
               	<el-input v-model="channel.channelName"  ></el-input>
               </el-form-item>
           		<el-form-item label="手机号">
           			<el-input v-model="channel.channelPhone" placeholder="长度8-13位"></el-input>
           		</el-form-item>
           		<el-form-item label="证件号码">
           			<el-input v-model="channel.channelIdNumber" placeholder="必须为数字"></el-input>
           		</el-form-item>
               <el-form-item label="开户行">
               	<el-input v-model="channel.channelBank"></el-input>
               </el-form-item>
               <el-form-item label="账号">
               	<el-input v-model="channel.channelBankAccount" placeholder="必须位数字"></el-input>
               </el-form-item>
               <el-form-item label="状态">
               	<template>
               	  <el-radio v-model="channel.channelStat" label="1">启用</el-radio>
               	  <el-radio v-model="channel.channelStat" label="0">禁用</el-radio>
               	</template>
               </el-form-item>

              </el-form>
             <div slot="footer" class="dialog-footer">
               <el-button @click="addShopFormVisible = false">取 消</el-button>
               <el-button type="primary" @click="addchannelOk">添加</el-button>
             </div>
           </el-dialog>
    </div>

  </div>


</template>

<script>
  export default {
    name: 'channel',
    data() {
      return {
        channels: [],
        channel: {
          channelId: "",
          channelName: "",
          channelPhone: "",
          channelStat: "",
          channelConsume: "",
          channelRecharge: "",
          channelMemberNum: "",
          channelIdNumber: "",
          channelBank: "",
          channelBankAccount: ""
        },
        current: "",
        size: "",
        pages: null,
        multipleSelection: [],
        likeName:"",
        addShopFormVisible:false,
        updateShopFormVisible:false,
      }
    },
    methods: {
      // 初始化页面查询生成
      getAllchannel(current, size) {
        this.$http.get("/channel/findAllChannel", {
          params: {
            current: current,
            size: size
          }
        }).then(resp => {
          console.log(resp)
          this.channels = resp.data.data.records
          this.pages = resp.data.data
          this.current = resp.data.data.current
          this.size = resp.data.data.size
        })
      },
      IsKill(row, column) {
        if (row.channelStat == 1) {
          return "已启用"
        } else {
          return "已停用"
        }
      },
     //修改渠道商方法
      updatechannel(channel){
          this.channel=channel
           this.updateShopFormVisible=true;
      },
      updateWarOK(){
        this.$http.post("/channel/updateChannle",{channelform :this.channel}).then(resp=>{
          this.channel={};
          this.updateShopFormVisible=false;
          alert(resp.data.message);
      })
      },
      // 模糊查询方法
      findchannelby(){
        this.findchannelbylike(1,4)
      },
      findchannelbylike(current,size){
        this.$http.get("/channel/findChannelbylike",{
          params: {
            current:current,
            size: size,
            likeName:this.likeName
          }
        }).then(resp=>{
         this.channels = resp.data.data.records
         this.pages = resp.data.data
         this.current = resp.data.data.current
         this.size = resp.data.data.size
        })
      },
      // 删除方法
      delechannel(){
        console.log(this.multipleSelection)
        this.$http.post("/channel/delchnnelById",{listchannel:this.multipleSelection}).then(resp=>{
          alert(resp.data.message)
          location.reload();
        })
      },
      // 新增方法
      addchannel(){
           this.addShopFormVisible=true;
      },
      addchannelOk(){
        this.$http.post("/channel/addChannle",{
          channelName:this.channel.channelName,
          channelPhone:this.channel.channelPhone,
          channelIdNumber:this.channel.channelIdNumber,
          channelBank:this.channel.channelBank,
          channelBankAccount:this.channel.channelBankAccount,
          channelStat:this.channel.channelStat,
        }).then(resp=>{
          alert(resp.data.message)
         this.addShopFormVisible=false;
          location.reload();
        })

      },
      shopClose(){
     this.addShopFormVisible=false;
     this.updateShopFormVisible=false;
      },
      tableRowClassName({
        row,
        rowIndex
      }) {
        if (row.channelStat == 0) {
          return 'warning-row'
        }
      },
      // 分页选择
      handleCurrentChange(current) {
        if(this.likeName==""){
           this.getAllchannel(current, this.size)
        }else{
          this.findchannelbylike(current, this.size)
        }

      },
      handleSizeChange(size) {
       if(this.likeName==""){
          this.getAllchannel(this.current, size)
       }else{
         this.findchannelbylike(this.current, size)
       }
      }, //多选框选择的对象
      handleSelectionChange(val) {
        this.multipleSelection = val;
      },
    },
    created() {
      this.getAllchannel(1, 4)
    },
    watch:{
      'likeName':function(){
         this.findchannelbylike(1,4);
      }
    }

  }
</script>

<style>
  .channel_top {
    position: absolute;
    height: 50px;
    width: 1030px;
    left: 150px;
    top: 0px;
    background-color: skyblue;
  }

  .el-table .warning-row {
    background: yellow;
  }
  .table1 {
    position: absolute;
    top: 50px;
    left: 150px;
  }
</style>
